package com.happyhome.services;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.happyhome.constants.AppConstant;
import com.happyhome.constants.ComTxManagerName;
import com.happyhome.dao.ParameterDao;
import com.happyhome.datamodel.Parameter;

@Service
public class ParameterServiceImpl implements ParameterService{
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory.getLogger(ParameterServiceImpl.class);
	
	@Autowired
    private ParameterDao parameterDao;

	@Override
	public List<Parameter> getDataConfigureForCavas() {
		List<Parameter> listResult = new ArrayList<Parameter>();
		Parameter houseParameter = parameterDao.getParameterByCode(AppConstant.HOUSES_CODE);
		Parameter roomParameter = parameterDao.getParameterByCode(AppConstant.ROOMS_CODE);
		Parameter newsParameter = parameterDao.getParameterByCode(AppConstant.NEWS_CODE);
		
		listResult.add(houseParameter);
		listResult.add(roomParameter);
		listResult.add(newsParameter);
		
		return listResult;
	}

	@Override
	public Parameter getParameterByCode(String code) {
		return parameterDao.getParameterByCode(code);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void merge(Parameter parameter) {
		parameterDao.merge(parameter);
	}

}
